<template>
    <Layout>
        <div class="announcement-details">
            <!-- 面包屑导航 -->
            <div class="breadcrumb">
                当前位置：<router-link to="/home" class="breadcrumb-link">首页</router-link> > <router-link to="/notices-and-announcements" class="breadcrumb-link">媒体报道</router-link> > <span class="breadcrumb-current">详情</span>
            </div>

            <div class="announcement-content">
                <h1 class="title">{{ mediaView.title }}</h1>
                
                <div class="meta-info">
                    <span><el-icon><Calendar /></el-icon>{{ formatDate(mediaView.publishTime) }}</span>
                    <span><el-icon><User /></el-icon>{{ mediaView.author }}</span>
                    <span><el-icon><View /></el-icon>{{ mediaView.views }} 次浏览</span>
                </div>

                <div class="content">
                    <div v-if="mediaView.imageUrl" class="image-container">
                        <el-image :src="mediaView.imageUrl" fit="contain"></el-image>
                    </div>
                    <div class="text-content" v-html="mediaView.content"></div>
                </div>
            </div>
        </div>

        <!-- 留言板 -->
        <MessageBoard />
    </Layout>
</template>

<script setup>
import Layout from '@/components/Layout.vue'
import MessageBoard from '@/components/MessageBoard.vue'
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { Calendar, User, View } from '@element-plus/icons-vue'
import axios from 'axios'

const route = useRoute()
const mediaView = ref({
    title: '',
    content: '',
    author: '',
    publishTime: '',
    views: 0,
    imageUrl: ''
})

const formatDate = (date) => {
    if (!date) return ''
    return new Date(date).toLocaleDateString('zh-CN')
}

onMounted(async () => {
    const id = route.params.id
    try {
        const response = await axios.get(`/api/mediea/${id}`)
        if (response.data) {
            mediaView.value = response.data
        }
    } catch (error) {
        console.error('获取媒体报道详情失败:', error)
    }
})
</script>

<style scoped>
.announcement-details {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.breadcrumb {
    margin-bottom: 20px;
    color: #666;
    font-size: 14px;
}

.breadcrumb-link {
    color: #dd2b2b;
    text-decoration: none;
}

.breadcrumb-link:hover {
    color: #ff4d4d;
}

.breadcrumb-current {
    color: #dd2b2b;
}

.announcement-content {
    background: #fff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
}

.title {
    text-align: center;
    font-size: 24px;
    color: #303133;
    margin-bottom: 20px;
}

.meta-info {
    display: flex;
    justify-content: center;
    gap: 30px;
    color: #909399;
    font-size: 14px;
    margin-bottom: 30px;
    border-bottom: 1px solid #EBEEF5;
    padding-bottom: 20px;
}

.meta-info span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.content {
    color: #606266;
    line-height: 1.8;
}

.image-container {
    margin: 20px 0;
    text-align: center;
}

.image-container .el-image {
    max-width: 100%;
    border-radius: 4px;
}

.text-content {
    font-size: 16px;
    text-align: justify;
}
</style>
